function Pop(opts) {
  var self = this;
  var size = Pop.__xDocSize();

  var width = (opts && opts.w) ? opts.w : 400;
  var height = (opts && opts.h) ? opts.h : 320;
  var pos = (opts && opts.p) ? opts.p : [(size.w / 2) - (width / 2), (size.h / 2) - (height / 2)];

  var con, bar, elm;
  con = document.createElement('div');
  
  this._bg = document.createElement('div');
  this._bg.style.background = 'url(pop/bb.png) repeat scroll center top transparent';
  this._bg.style.position = 'absolute';
  this._bg.style.top = 0;
  this._bg.style.left = 0;
  this._bg.style.width = size.w + 'px';
  this._bg.style.height = size.h + 'px';
  document.body.appendChild(this._bg);
  
  con = document.createElement('div');
  con.style.position = 'absolute';
  con.style.width = width + 'px';
  if (opts && opts.h) {
    con.style.height = height + 'px';
  }
  con.style.background = '#fff';
  con.style.top = pos[1] + 'px';
  con.style.left = pos[0] + 'px';
  con.style.border = '1px solid #ddd';
  con.style.borderTop = 0;
  this._bg.appendChild(con);
  
  if (opts && opts.b == 1) {
    bar = document.createElement('div');
    bar.style.width = '100%';
    bar.style.height = '30px';
    bar.style.lineHeight = '30px';
    bar.style.verticalAlign = 'middle';
    bar.style.background = '#333';
//    bar.style.paddingLeft = '5px';
    bar.style.color = '#fff';
    bar.style.fontWeight = 'bold';
    con.appendChild(bar);
    
    if (opts && opts.t != '') {
      bar.appendChild(document.createTextNode('\u00a0' + opts.t));
    }
    
    elm = document.createElement('img');
    elm.style.margin = '2px 5px 0 0';
    elm.src = 'pop/del.png';
    elm.style.cursor = 'pointer';
    elm.style.position = 'relative';
    elm.style.cssFloat = 'right';
    elm.onclick = function() {
      self.close();
    };
    bar.appendChild(elm);
  } else {
    this._bg.onclick = function() {
      self.close();
    };
  }
  
  this._content = document.createElement('div');
  con.appendChild(this._content);
};

Pop.prototype.append = function(elm) {
  this._content.appendChild(elm);
}

Pop.prototype.close = function() {
  document.body.removeChild(this._bg);
}

Pop.prototype.is_on = function() {
  return this._bg.parentNode == document.body;
}

Pop.__xDocSize = function() {
  var b = document.body, e = document.documentElement;
  var esw = 0, eow = 0, bsw = 0, bow = 0, esh = 0, eoh = 0, bsh = 0, boh = 0;
  if (e) {
    esw = e.scrollWidth;
    eow = e.offsetWidth;
    esh = e.scrollHeight;
    eoh = e.offsetHeight;
  }
  if (b) {
    bsw = b.scrollWidth;
    bow = b.offsetWidth;
    bsh = b.scrollHeight;
    boh = b.offsetHeight;
  }
  return {
    w : Math.max(esw, eow, bsw, bow),
    h : Math.max(esh, eoh, bsh, boh)
  };
};
